from fake_useragent import UserAgent
import urllib.request as ur
import re
ua = UserAgent(verify_ssl=False)
headers=('User-Agent',ua.random)
def useful_ip():
    place='江苏'
    area=ur.quote(place)
    ip_url='http://pvt.daxiangdaili.com/ip/?tid=558670771263312&num=10&area='+area+'&filter=on'
    data=ur.urlopen(ip_url).read().decode('UTF-8','ignore')
    pat=re.compile('(\d+\.\d+\.\d+\.\d+:\d+)')
    ip_data=pat.findall(data)
    for ip in ip_data:
        proxy=ur.ProxyHandler({'http':ip})
        opener=ur.build_opener(proxy,ur.HTTPHandler)
        opener.addheaders=[headers]
        k=opener.open('https://www.baidu.com/').read().decode('utf-8','ignore')
        if len(k)>0:
            return ip



